package com.dai.mq.listener;

import com.dai.enu.RabbitmqEnum;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class RabbitMqLister {
    @RabbitListener(queues = RabbitmqEnum.GENERL_QUEUE_RABBITMQ)
    public void zs(String mess) {
        System.out.println("现在的消息是" + mess);
    }

    @RabbitListener(queues = RabbitmqEnum.GENERL_QUEUE_RABBITMQ)
    public void ls(String mess) {
        System.err.println("现在的消息是" + mess);
    }

//    监听绑定队列
    @RabbitListener(queues = RabbitmqEnum.GENERL_QUEUE_ONE)
    public void wangwu(String mess) {
        System.out.println("现在监听的是王五队列,监听的消息是" + mess);
    }

    @RabbitListener(queues = RabbitmqEnum.GENERL_QUEUE_TWO)
    public void zhaoliu(String mess) {
        System.err.println("现在监听的是赵六队列,监听的消息是" + mess);
    }

    // 路由监听
    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = RabbitmqEnum.QUEUE_DIRECT_ONE),
            exchange = @Exchange(name = RabbitmqEnum.DIRECT_EXCHANGE, type = ExchangeTypes.DIRECT),
            key = RabbitmqEnum.QUEUE_KEY_RED))
    public void DirectExchange(String mess) {
        System.out.println("现在监听的是赵六，返回的信息是" + mess);
    }
    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = RabbitmqEnum.QUEUE_DIRECT_TWO),
            exchange = @Exchange(value = RabbitmqEnum.DIRECT_EXCHANGE, type = ExchangeTypes.DIRECT),
            key = RabbitmqEnum.QUEUE_KEY_RED))
    public void DirectExchangeSun(String mess) {
        System.err.println("现在监听的是孙七,返回的信息是" + mess);
    }
}
